package com.ruoyi.guide.controller;

import java.util.List;

import com.ruoyi.utils.UrlUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.guide.domain.XlkjGuide;
import com.ruoyi.guide.service.IXlkjGuideService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 办事指南Controller
 *
 * @author wang
 * @date 2022-01-15
 */
@RestController
@RequestMapping("/guide/guide")
public class XlkjGuideController extends BaseController
{
    @Autowired
    private IXlkjGuideService xlkjGuideService;

    /**
     * 查询办事指南列表
     */
    @PreAuthorize("@ss.hasPermi('guide:guide:list')")
    @GetMapping("/list")
    public TableDataInfo list(XlkjGuide xlkjGuide)
    {
        startPage();
        List<XlkjGuide> list = xlkjGuideService.selectXlkjGuideList(xlkjGuide);
        for(XlkjGuide guide:list){
            if(guide.getEnclosure()!=null && !guide.getEnclosure().equals("")){
                guide.setEnclosure(UrlUtils.getUrl() + guide.getEnclosure());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出办事指南列表
     */
    @PreAuthorize("@ss.hasPermi('guide:guide:export')")
    @Log(title = "办事指南", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(XlkjGuide xlkjGuide)
    {
        List<XlkjGuide> list = xlkjGuideService.selectXlkjGuideList(xlkjGuide);
        ExcelUtil<XlkjGuide> util = new ExcelUtil<XlkjGuide>(XlkjGuide.class);
        return util.exportExcel(list, "办事指南数据");
    }

    /**
     * 获取办事指南详细信息
     */
    @PreAuthorize("@ss.hasPermi('guide:guide:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(xlkjGuideService.selectXlkjGuideById(id));
    }

    /**
     * 新增办事指南
     */
    @PreAuthorize("@ss.hasPermi('guide:guide:add')")
    @Log(title = "办事指南", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XlkjGuide xlkjGuide)
    {
        return toAjax(xlkjGuideService.insertXlkjGuide(xlkjGuide));
    }

    /**
     * 修改办事指南
     */
    @PreAuthorize("@ss.hasPermi('guide:guide:edit')")
    @Log(title = "办事指南", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XlkjGuide xlkjGuide)
    {
        return toAjax(xlkjGuideService.updateXlkjGuide(xlkjGuide));
    }

    /**
     * 删除办事指南
     */
    @PreAuthorize("@ss.hasPermi('guide:guide:remove')")
    @Log(title = "办事指南", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xlkjGuideService.deleteXlkjGuideByIds(ids));
    }
}
